package com.yinian.cart.controller;


import com.yinian.cart.service.ProductList.ProductListService;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController//把方法的返回值返回到页面上
@RequestMapping("/Manage")
public class ManageController {

    @Autowired
    private ProductListService productListService;

    @GetMapping("/test")
    public String test(){
        return "这是test";
    }

    @GetMapping("/getAllProductList")
    public String getAllProductList(){
        JSONArray jsonArray = productListService.findAllProductList();
        JSONObject jsonObject = new JSONObject();
        if (jsonArray!=null){
            jsonObject.append("data",jsonArray);
            jsonObject.append("status","ok");
        }else{
            jsonObject.append("status","no");
        }
        return jsonObject.toString();
    }
}
